package modelLayer;

import java.io.Serializable;



@SuppressWarnings("serial")
public class PartStatus implements Serializable {

	private int partStatusID;
	private int statusDay; //finish no. products made for a day
	private int ownFail;
	private int machineFail;
	private int pastOver;
	private String comments;
	private int finishNumberOfPlates;	
	private Product product;
	private Pallet pallet;	
	private Status status;
	
	
	public PartStatus()
	{
		
		this.statusDay = 0;
		this.ownFail = 0;
		this.machineFail = 0;
		this.pastOver = 0;
		this.finishNumberOfPlates = 0;
		product = null;
		
	}

	
	public void setProduct(Product product)
	{
		this.product = product;
	}
	
	public Product getProduct()
	{
		return product;
	}

	public int getPartStatusID() {
		return partStatusID;
	}


	public void setPartStatusID(int partStatusID) {
		this.partStatusID = partStatusID;
	}
	
	//calculate the existing 
	public void setSupplierFail(int supplierFail) {
		if(pallet != null){
		pallet.setSupplierFail(supplierFail);
		}		
	}


	
	public int getStatusDay() {
		calculateDayStatus();
		return statusDay;
	}


	public void setStatusDay(int statusDay) {
		this.statusDay = statusDay;
	}
	
	public int updateStatusDay(int statusDay){
		return this.statusDay =+ statusDay;
	}


	public int getOwnFail() {
		return ownFail;
	}


	public int updateOwnFail(int ownFail) {
		return this.ownFail =+ ownFail;
	}
	
	public void setOwnFail(int ownFail){
		this.ownFail = ownFail;
	}

	public int getMachineFail() {
		return machineFail;
	}


	public void setMachineFail(int machineFail) {
		this.machineFail = machineFail;
	}
	
	public int updateMachineFail(int machineFail)
	{
		
		return this.machineFail =+ machineFail;
	}

	public int getPastOver() {
		return pastOver;
	}

	public void setPastOver(int pastOver) {
		this.pastOver = pastOver;
	}
	
	public int updatePastOver(int pastOver)
	{
		return this.pastOver =+ pastOver; 
	}


	public String getComments() {
		return comments;
	}


	public void setComments(String comments) {
		this.comments = comments;
	}


	public int getFinishNumberOfPlates() {
		return finishNumberOfPlates;
	}


	public void setFinishNumberOfPlates(int finishNumberOfPlates) {
		pallet.setNumberOfPlates(finishNumberOfPlates);
		this.finishNumberOfPlates = finishNumberOfPlates;
	}
	
	//calculate the partStatus finish no. of made plates
	//System out println to test
	public int calculateDayStatus() 
	{
		int i = -1;
		Pallet pa = pallet;
		if(pa != null)
		{
			//numbers on Pallet minus supplierFails minus finishNoOfPlates
			//minus ownFail minus machineFail
			i = pa.getNumberOfPlates() - pa.getSupplierFail() 
					- finishNumberOfPlates - ownFail - machineFail;
			
			System.out.println("Product: " + product.getProductID());
			System.out.println("");
			System.out.println("no. of plates on Pallet............ : "+pa.getNumberOfPlates());
			System.out.println("no. of supplier fails.............. : "+pa.getSupplierFail());
			System.out.println("the finish no of plates on Pallet.. : "+ finishNumberOfPlates);
			System.out.println("no. of ownFail..................... : "+ownFail);
			System.out.println("no. of machineFail................. : "+machineFail);
			System.out.println("no. of product made................ : "+i);
			
			System.out.println("Calculating successed");			
			
			this.statusDay = i;
		}
		
		
		return i;
	}
	
	
	public void setPallet(Pallet pa)
	{
		this.pallet = pa;
	}
	
	public Pallet getPallet()
	{
		return pallet;
	}


	public Status getStatus() {
		return status;
	}


	public void setStatus(Status status) {
		this.status = status;
	}
	
	
//	//Controls the Pallets on the partOrder
//	public void addPallet(Pallet pallet)
//	{
//		this.pallet.add(pallet);
//	}
//	
//	public Pallet getPallet(int palletID, String batchNo)
//	{
//		int i = 0;
//		boolean found = false;
//		Pallet p = null;
//		
//		while(i < pallet.size() && !found)
//		{
//			p = pallet.get(i);
//			if(p.getPalletID() == palletID && p.getBatchNo().equalsIgnoreCase(batchNo))
//			{
//				found = true;				
//			}
//			i++;
//		}
//		return p;
//		
//	}
//	
//	public boolean removePallet(int palletID, String batchNo)
//	{
//		Pallet p = getPallet(palletID, batchNo);
//		boolean removed = false;
//		
//		if(p != null)
//		{
//			this.pallet.remove(p);
//			removed = true;
//		}
//		
//		return removed;
//	}
	
	
}
